package com.yuedao.sender.service1;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import cn.ydx.protobuf.OTIpcDef;

import com.yuedao.sender.model.BaseInfoCompany;
import com.yuedao.sender.model.RatedDriver;
import com.yuedao.sender.model.RatedDriverPunish;
import com.yuedao.sender.model.RatedPassenger;
import com.yuedao.sender.model.RatedPassengerComplaint;
import com.yuedao.sender.service.RatedDriverPunishRepository;
import com.yuedao.sender.service.RatedDriverRepository;
import com.yuedao.sender.service.RatedPassengerComplaintRepository;
import com.yuedao.sender.service.RatedPassengerRepository;

/**
 * @author xfm 2018年5月16日
 */

@Service
public class RateService extends BaseService {

	@Value("${target.ratepassenger.url}")
	private String passengerURL;

	@Value("${target.ratedpassengercomplaint.url}")
	private String passengerComplaintURL;

	@Value("${target.rateddriverpunish.url}")
	private String driverPunishURL;

	@Value("${target.rateddriver.url}")
	private String driverURL;

	/**
	 * A.8.1 乘客评价信息接口
	 */
	public String sendRatedPassenger(List<RatedPassenger> list) {
		
		if (list.size() > 0) {
			OTIpcDef.OTIpc.Builder builder = OTIpcDef.OTIpc.newBuilder()
					.setCompanyId(companyId).setSource(companySource)
					.setIPCType(OTIpcDef.IpcType.ratedPassenger);
			for (RatedPassenger data : list) {
				builder.addRatedPassenger(RatedPassenger.convert(data));
			}
			OTIpcDef.OTIpc otIpc = builder.build();
			return super.compressAndSend(passengerURL, otIpc);
		}
		return null;
	}

	/**
	 * A.8.2 乘客投诉信息接口
	 */
	public String sendRatedPassengerComplaint(List<RatedPassengerComplaint> list ) {
		
		if (list.size() > 0) {
			OTIpcDef.OTIpc.Builder builder = OTIpcDef.OTIpc.newBuilder()
					.setCompanyId(companyId).setSource(companySource)
					.setIPCType(OTIpcDef.IpcType.ratedPassengerComplaint);
			for (RatedPassengerComplaint data : list) {
				builder.addRatedPassengerComplaint(RatedPassengerComplaint
						.convert(data));
			}
			OTIpcDef.OTIpc otIpc = builder.build();
			return super.compressAndSend(passengerComplaintURL, otIpc);
		}
		return null;
	}

	/**
	 * A.8.3 驾驶员处罚信息接口
	 */
	public String sendRatedDriverPunish(List<RatedDriverPunish> list ) {
		
		if (list.size() > 0) {
			OTIpcDef.OTIpc.Builder builder = OTIpcDef.OTIpc.newBuilder()
					.setCompanyId(companyId).setSource(companySource)
					.setIPCType(OTIpcDef.IpcType.ratedDriverPunish);
			for (RatedDriverPunish data : list) {
				builder.addRatedDriverPunish(RatedDriverPunish.convert(data));
			}
			OTIpcDef.OTIpc otIpc = builder.build();
			return super.compressAndSend(driverPunishURL, otIpc);
		}
		return null;
	}

	/**
	 * A.8.4 驾驶员信誉信息接口
	 */
	public String sendRatedDriver(List<RatedDriver> list) {
		
		if (list.size() > 0) {
			OTIpcDef.OTIpc.Builder builder = OTIpcDef.OTIpc.newBuilder()
					.setCompanyId(companyId).setSource(companySource)
					.setIPCType(OTIpcDef.IpcType.ratedDriver);
			for (RatedDriver data : list) {
				builder.addRatedDriver(RatedDriver.convert(data));
			}
			OTIpcDef.OTIpc otIpc = builder.build();
			return super.compressAndSend(driverURL, otIpc);
		}
		return null;
	}

}
